#include <iomanip>
#include <iostream>
using namespace std;

const int STACK_SIZE = 100;

class Stack
{
    int top;                //数据成员：栈顶指针
    int buffer[STACK_SIZE]; //数据成员：栈空间
public:
    //构造函数，当创建对象时自动调用，用来初始化。函数名应该和类名一致
    Stack() { top = 0; }
    int length() { return top; }
    bool pop(int &e);

    bool push(int element)
    {
        if (top == STACK_SIZE)
        {
            cout << "Stack is overflow!\n";
            return false;
        }
        else
        {
            buffer[top] = element;
            top++;
            return true;
        }
    }
};

bool Stack::pop(int &e)
{
    if (top == 0)
    {
        cout << "Stack is empty!\n";
        return false;
    }
    else
    {
        e = buffer[--top];
        return true;
    }
}